﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XNAFight.Scene.Core
{
    public class TextMenuItem : MenuItem
    {
        #region CHAMPS

        // Ratio de la taille du texte
        private float scale;
        // Texte de l'élément
        private string text;

        // Couleur d'un element neutre
        private Color neutral_color;
        // Couleur d'un element selectionné
        private Color selected_color;

        #endregion

        #region PROPRIETES

        public string Text
        {
            get { return text; }
        }

        public Color NeutralColor
        {
            get { return neutral_color; }
            set { neutral_color = value; }
        }
        public Color SelectedColor
        {
            get { return selected_color; }
            set { selected_color = value; }
        }

        #endregion

        #region INITIALISATION

        public TextMenuItem(Vector2 _pos, string _text, float _scale = 1) : base (_pos)
        {
            text = _text;
            scale = _scale;

            neutral_color = Color.DarkGray;
            selected_color = Color.Black;
        }

        #endregion

        #region UPDATE / DRAW

        public override void Update(GameTime _gameTime, bool _is_selected)
        { }
        public override void Update(GameTime _gameTime, List<int> _player_ids)
        { }

        public override void Draw(GameTime _gameTime, bool _is_selected)
        {
            Color color;
            if (_is_selected)
            {
                color = selected_color;
            }
            else
            {
                color = neutral_color;
            }
            
            var origin = new Vector2(0, CommonContent.DefaultFont.LineSpacing / 2f);
            CommonContent.SpriteBatch.DrawString(CommonContent.DefaultFont, text, position, color, 0, origin, scale, SpriteEffects.None, 0);
        }

        public override void Draw(GameTime _gameTime, List<int> _player_ids)
        {
            Color color;
            string new_text = text;
            if (_player_ids.Count > 0)
            {
                color = selected_color;
                for (int i = 0; i < _player_ids.Count; i++)
                {
                    new_text += "(" + _player_ids[i] + ")";
                }
            }
            else
            {
                color = neutral_color;
            }

            var origin = new Vector2(0, CommonContent.DefaultFont.LineSpacing / 2f);
            CommonContent.SpriteBatch.DrawString(CommonContent.DefaultFont, new_text, position, color, 0, origin, scale, SpriteEffects.None, 0);
        }

        #endregion

        #region AUTRES METHODES

        // Donne la hauteur du texte à l'écran
        public int GetHeight(SpriteFont _font)
        {
            return (int)(_font.Spacing * scale);
        }

        // Donne la largeur du texte à l'écran
        public int GetWidth(SpriteFont _font)
        {
            return (int)(_font.MeasureString(text).X * scale);
        }

        #endregion
    }
}
